package cn.wps.moffice.main.cloud.storage.core.service.internal.evernote; import android.net.Uri; import android.text.TextUtils; import android.util.Log; import android.util.SparseArray; import cn.wps.moffice.OfficeApp; import cn.wps.moffice.main.cloud.storage.core.service.internal.AbsCSAPI; import cn.wps.moffice.main.cloud.storage.model.CSConfig; import cn.wps.moffice.main.cloud.storage.model.CSFileData; import cn.wps.moffice.main.cloud.storage.model.CSFileRecord; import cn.wps.moffice.main.cloud.storage.model.CSSession; import cn.wps.moffice_eng.R; import cn.wps.util.JSONUtil; import com.mopub.mobileads.InterstitialAdType; import defpackage.cqh; import defpackage.fqr; import defpackage.frg; import defpackage.wmt; import defpackage.wnz; import java.io.ByteArrayInputStream; import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.net.ssl.SSLException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.scribe.builder.ServiceBuilder; import org.scribe.builder.api.Api; import org.scribe.builder.api.EvernoteApi; import org.scribe.exceptions.OAuthConnectionException; import org.scribe.model.OAuthConstants; import org.scribe.model.Token; import org.scribe.model.Verifier; import org.scribe.oauth.OAuthService; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class EvernoteAPI extends AbsCSAPI { private HashMap<String, wmt.a> gmK; private HashMap<String, a> gmL; private wmt.a gmM; private wmt.a gmN; private wnz.a gmO; private wnx gmP; private String gmQ; private String gmR; private dgq gmS; private frg gmT; private long gmU; private wmw gmV; private long gmW; private String gmX; private wnv gmY; private CSFileData gmy; /* access modifiers changed from: package-private */ public class a { public long expiredTime; public String token; private a() { } /* synthetic */ a(EvernoteAPI evernoteAPI, byte b) { this(); } } public EvernoteAPI(String str) { super(str); this.gmK = null; this.gmL = null; this.gmM = null; this.gmN = null; this.gmO = null; this.gmP = null; this.gmQ = null; this.gmR = null; this.gmU = 0; this.gmW = 0; this.gmX = "resource:application/*"; this.gmY = null; this.gmK = new HashMap<>(); this.gmL = new HashMap<>(); this.gmT = new frg(); this.gmW = System.currentTimeMillis(); if (this.gmn != null) { bEG(); } } private wno Q(String str, String str2, String str3) throws fte { wmt.a bEI; try { String sY = frh.sY(str); String str4 = this.gmS.token; if (!TextUtils.isEmpty(sY)) { bEI = sQ(sY); str4 = a(sY, bEI); } else { bEI = bEI(); } wne a2 = bEI.a(str4, str, false, false, false, false); if (a2.wWP > 0) { throw new fte(-2); } List<wno> list = a2.wZS; if (list != null) { ArrayList arrayList = new ArrayList(); for (wno wno : list) { if (wno.xcT != null && !TextUtils.isEmpty(wno.xcT.fileName) && wno.xcT.fileName.trim().equals(str2)) { arrayList.add(wno); } } if (arrayList.size() != 1) { return null; } wno wno2 = (wno) arrayList.get(0); list.remove(list.indexOf(wno2)); wno2.xcT.fileName = str3; list.add(wno2); bEI.b(str4, a2); return wno2; } return null; } catch (wmo e) { fqn.c("EvernoteAPI", "rename", e); if (e.wVR == wml.PERMISSION_DENIED) { throw new fte(-4); } } catch (Exception e2) { fqn.c("EvernoteAPI", "rename", e2); } } private static CSFileData a(wne wne, String str) { CSFileData cSFileData = new CSFileData(); cSFileData.setFileId(wne.dxl); cSFileData.setPath(wne.dxl); cSFileData.setName(wne.title); cSFileData.setFolder(true); cSFileData.setRefreshTime(Long.valueOf(wne.wWO)); cSFileData.setCreateTime(Long.valueOf(wne.wWO)); cSFileData.setModifyTime(Long.valueOf(wne.wWO)); cSFileData.setFileSize((long) wne.wWM); cSFileData.setTag(true); cSFileData.setDrawableIconId(R.drawable.public_evernote_note_icon); if (!TextUtils.isEmpty(str)) { cSFileData.addParent(str); } return cSFileData; } private static CSFileData a(wno wno) { CSFileData cSFileData = new CSFileData(); cSFileData.setFileId(wno.xcN + "@_@" + wno.xcT.fileName.trim()); cSFileData.setFolder(false); cSFileData.setName(wno.xcT.fileName.trim()); cSFileData.setRefreshTime(Long.valueOf(wno.xcT.timestamp)); cSFileData.setCreateTime(Long.valueOf(wno.xcT.timestamp)); cSFileData.setModifyTime(Long.valueOf(frh.sX(wno.dxl))); cSFileData.setFileSize((long) wno.xcO.size); cSFileData.setMimeType(wno.xcP); cSFileData.setPath(cSFileData.getFileId()); cSFileData.addParent(wno.xcN); return cSFileData; } private String a(String str, wmt.a aVar) throws wmo, wmm, wmn, wod { a aVar2 = this.gmL.get(str); if (aVar2 == null || System.currentTimeMillis() > aVar2.expiredTime) { aVar.hp(str, this.gmS.token); wnx fYc = aVar.fYc(); String str2 = fYc.gnE; aVar2 = new a(this, (byte) 0); aVar2.expiredTime = fYc.xff; aVar2.token = str2; this.gmL.put(str, aVar2); } return aVar2.token; } private static Document a(Document document, String str, String str2) { NodeList elementsByTagName = document.getElementsByTagName("en-media"); int length = elementsByTagName.getLength(); for (int i = 0; i < length; i++) { Node namedItem = elementsByTagName.item(i).getAttributes().getNamedItem("hash"); if (namedItem != null && str.equals(namedItem.getNodeValue())) { namedItem.setNodeValue(str2); } } return document; } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private synchronized wmw a(wmt.a aVar, String str) throws wmo, wmn, wod { aVar.Yb(str); return aVar.fXU(); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void a(wmw wmw) { if (this.gmY != null) { ful.ac(Math.abs(this.gmY.xdO.wYM - wmw.wYp)); } } private boolean a(wmt.a aVar, String str, wmw wmw) throws wmo, wmn, wod { if (System.currentTimeMillis() > this.gmU) { this.gmU = System.currentTimeMillis() + 900000; return true; } this.gmV = a(aVar, str); if (aVar == this.gmM) { a(this.gmV); } return ((long) this.gmV.wWB) != ((long) wmw.wWB); } private boolean a(wne wne) { long j = 0; if (wne != null) { j = 0 + ((long) wne.wWM); List<wno> list = wne.wZS; if (list != null && list.size() > 0) { int i = 0; while (i < list.size()) { wno wno = list.get(i); i++; j = wno.xcO != null ? ((long) wno.xcO.size) + j : j; } } } return j > (ful.bHB() ? 104857600 : 26214400); } private void bEG() { try { this.gmS = (dgq) JSONUtil.instance(this.gmn.getToken(), dgq.class); } catch (Exception e) { e.printStackTrace(); } new Thread() { /* class cn.wps.moffice.main.cloud.storage.core.service.internal.evernote.EvernoteAPI.AnonymousClass1 */ public final void run() { int i = 2; while (EvernoteAPI.this.gmY == null && i > 0) { i--; try { EvernoteAPI evernoteAPI = EvernoteAPI.this; wnz.a bEL = EvernoteAPI.this.bEL(); bEL.Yg(EvernoteAPI.this.gmS.token); evernoteAPI.gmY = bEL.fZU(); EvernoteAPI.this.a((EvernoteAPI) EvernoteAPI.this.a((EvernoteAPI) EvernoteAPI.this.bEI(), (wmt.a) EvernoteAPI.this.gmS.token)); } catch (Exception e) { e.printStackTrace(); } } ful.mx((EvernoteAPI.this.gmY == null || EvernoteAPI.this.gmY.xdQ == null) ? false : true); } }.start(); } private OAuthService bEH() { int aEz = (this.gmn != null || eip.eSn == eix.UILanguage_chinese) ? ful.aEz() : 1; Class<? extends Api> cls = null; if (aEz == 1) { cls = EvernoteApi.class; } else if (aEz == 2) { cls = wmk.class; } return new ServiceBuilder().provider(cls).apiKey("kso-android-agent").apiSecret("a482e0cbbfe48048").callback("en-kso-android-agent://callback").build(); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private wmt.a bEI() { if (this.gmM == null) { try { String str = this.gmS.dxN; frh.cG(OfficeApp.arx()); frh.bEQ(); this.gmM = frh.ta(str); } catch (woq e) { fqn.c("EvernoteAPI", "getNoteStoreClient()", e); } } return this.gmM; } private wnx bEJ() { if (this.gmP == null) { try { wnz.a bEL = bEL(); if (bEL != null) { bEL.Yf(this.gmS.token); this.gmP = bEL.fZT(); } } catch (wmo e) { fqn.c("EvernoteAPI", "getBusinessAuthResult", e); } catch (wmn e2) { fqn.c("EvernoteAPI", "getBusinessAuthResult", e2); } catch (wod e3) { fqn.c("EvernoteAPI", "getBusinessAuthResult", e3); } } return this.gmP; } private wmt.a bEK() { if (this.gmN == null) { try { woo woo = new woo(bEJ().dxN); woo.xfL = 500000; this.gmN = new wmt.a(new woe(woo)); } catch (woq e) { fqn.c("EvernoteAPI", "getBusinessNoteStoreClient", e); } } return this.gmN; } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private wnz.a bEL() { if (this.gmO == null) { try { this.gmO = frh.tb(this.gmS.dxN); } catch (wod e) { fqn.c("EvernoteAPI", "getUserStoreClient", e); } } return this.gmO; } private List<wnd> bEM() { try { frg.a<List<wnd>> aVar = this.gmT.gna; wmw wmw = aVar.gnf; T t = aVar.gng; if (wmw != null && t != null && !a(bEI(), this.gmS.token, wmw)) { return t; } wmt.a bEI = bEI(); bEI.Yd(this.gmS.token); T t2 = (T) bEI.fYb(); if (this.gmV == null) { this.gmV = a(bEI(), this.gmS.token); } frg frg = this.gmT; frg.gna.gnf = this.gmV; frg.gna.gng = t2; return t2; } catch (Exception e) { fqn.c("EvernoteAPI", "getLinkedNoteBooks", e); return null; } catch (OutOfMemoryError e2) { fqn.c("EvernoteAPI", "getLinkedNoteBooks OutOfMemoryError", e2); return null; } } private List<wnh> bEN() { try { frg.a<List<wnh>> aVar = this.gmT.gnb; wmw wmw = aVar.gnf; T t = aVar.gng; if (wmw != null && t != null && !a(bEI(), this.gmS.token, wmw)) { return t; } wmt.a bEI = bEI(); bEI.Yc(this.gmS.token); T t2 = (T) bEI.fXV(); if (this.gmV == null) { this.gmV = a(bEI(), this.gmS.token); } frg frg = this.gmT; frg.gnb.gnf = this.gmV; frg.gnb.gng = t2; return t2; } catch (Exception e) { fqn.c("EvernoteAPI", "getNoteBooks", e); return new ArrayList(); } } private void bEO() { try { wmt.a bEI = bEI(); bEI.a(this.gmS.token, new wmq(), false); Map<String, Integer> map = bEI.fXX().wVZ; if (map != null) { int i = 0; for (Map.Entry<String, Integer> entry : map.entrySet()) { i = entry.getValue().intValue() + i; } ful.wG(i); } } catch (Exception e) { fqn.c("EvernoteAPI", "loadNoteCounts", e); } } private ArrayList<wne> bEP() throws fte { ArrayList<wne> arrayList = new ArrayList<>(); try { frg.a<List<wne>> aVar = this.gmT.gnd; if (aVar == null || aVar.gnf == null || aVar.gng == null || a(bEI(), this.gmS.token, aVar.gnf)) { wmq wmq = new wmq(); wmq.setOrder(wng.UPDATED.value); wmq.JA(false); wmq.wWl = this.gmX; T t = (T) bEI().a(this.gmS.token, wmq, 0, 3000).wWy; if (this.gmV == null) { this.gmV = a(bEI(), this.gmS.token); } frg frg = this.gmT; frg.gnd.gnf = this.gmV; frg.gnd.gng = t; arrayList.addAll(t); return arrayList; } arrayList.addAll(aVar.gng); return arrayList; } catch (wmm e) { fqn.c("EvernoteAPI", "searchNotes", e); throw new fte(-2); } catch (woq e2) { fqn.c("EvernoteAPI", "searchNotes", e2); throw new fte(-5, e2); } catch (Exception e3) { fqn.c("EvernoteAPI", "searchNotes", e3); } } private List<wno> bJ(String str, String str2) throws fte { wmt.a bEI; try { String sY = frh.sY(str); String str3 = this.gmS.token; if (!TextUtils.isEmpty(sY)) { bEI = sQ(sY); str3 = a(sY, bEI); } else { bEI = bEI(); } wne a2 = bEI.a(str3, str, false, false, false, false); if (a2.wWP > 0) { throw new fte(-2); } List<wno> list = a2.wZS; ArrayList arrayList = new ArrayList(); if (list != null) { for (int i = 0; i < list.size(); i++) { wno wno = list.get(i); if (wno.xcT != null && !TextUtils.isEmpty(wno.xcT.fileName) && wno.xcT.fileName.trim().equals(str2)) { arrayList.add(wno); } } } if (arrayList.size() > 0) { return arrayList; } throw new fte(-2); } catch (wmm e) { fqn.c("EvernoteAPI", "getResourceDataByName", e); throw new fte(-2); } catch (fte e2) { fqn.c("EvernoteAPI", "getResourceDataByName", e2); throw new fte(-2); } catch (woq e3) { fqn.c("EvernoteAPI", "getResourceDataByName", e3); throw new fte(-5, e3); } catch (Exception e4) { fqn.c("EvernoteAPI", "getResourceDataByName", e4); return null; } } private byte[] c(String str, String str2, long j) throws fte { wmt.a bEI; try { String sY = frh.sY(str); String str3 = this.gmS.token; if (!TextUtils.isEmpty(sY)) { bEI = sQ(sY); str3 = a(sY, bEI); } else { bEI = bEI(); } wne a2 = bEI.a(str3, str, false, false, false, false); if (a2.wWP > 0) { throw new fte(-2); } List<wno> list = a2.wZS; if (list != null) { for (int i = 0; i < list.size(); i++) { wno wno = list.get(i); if (wno.xcT != null && !TextUtils.isEmpty(wno.xcT.fileName) && wno.xcT.fileName.trim().equals(str2) && j == frh.sX(wno.dxl)) { bEI.ho(str3, wno.dxl); return bEI.fXZ(); } } } throw new fte(-2); } catch (wmm e) { fqn.c("EvernoteAPI", "getResourceData", e); throw new fte(-2); } catch (fte e2) { fqn.c("EvernoteAPI", "getResourceData", e2); throw new fte(-2); } catch (Exception e3) { fqn.c("EvernoteAPI", "getResourceData", e3); return null; } } private wno d(String str, String str2, File file) throws fte { wmt.a bEI; wno wno; try { String sY = frh.sY(str); String str3 = this.gmS.token; if (!TextUtils.isEmpty(sY)) { bEI = sQ(sY); str3 = a(sY, bEI); } else { bEI = bEI(); } wne a2 = bEI.a(str3, str, true, false, false, false); if (a2.wWP > 0) { throw new fte(-2); } List<wno> list = a2.wZS; if (list != null) { Iterator<wno> it = list.iterator(); while (true) { if (!it.hasNext()) { wno = null; break; } wno next = it.next(); if (!(next.xcT == null || TextUtils.isEmpty(next.xcT.fileName) || !next.xcT.fileName.trim().equals(str2))) { wno = next; break; } } if (wno != null) { list.remove(wno); } wno wno2 = new wno(); wnb wnb = new wnb(); wnb.wZx = frh.S(file); wnb.wZw = frh.R(file); wnb.setSize((int) file.length()); wnp wnp = new wnp(); wnp.xap = "file://" + file.getAbsolutePath(); wnp.fileName = str2; wnp.JD(true); wno2.xcP = fqr.b.st(str2).mimeType; wno2.xcO = wnb; wno2.xcT = wnp; a2.b(wno2); if (a(a2)) { throw new fte(-804); } String str4 = a2.content; String B = frh.B(wno2.xcO.wZw); String B2 = (wno == null || wno.xcO == null) ? null : frh.B(wno.xcO.wZw); if (B2 != null && !B2.equals(B)) { DocumentBuilder newDocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(str4.getBytes()); str4 = frh.a(a(newDocumentBuilder.parse(byteArrayInputStream), B2, B)); byteArrayInputStream.close(); StringBuffer stringBuffer = new StringBuffer(str4); if (!TextUtils.isEmpty(str4) && !str4.contains("<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">")) { stringBuffer.insert(stringBuffer.indexOf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") + 38, "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">"); str4 = stringBuffer.toString(); } } a2.content = str4; bEI.b(str3, a2); List<wno> list2 = bEI.a(str3, str, false, false, false, false).wZS; for (int i = 0; i < list2.size(); i++) { wno wno3 = list2.get(i); if (!(wno3.xcT == null || TextUtils.isEmpty(wno3.xcT.fileName) || !wno3.xcT.fileName.trim().equals(str2))) { return wno3; } } return wno2; } return null; } catch (wmo e) { fqn.c("EvernoteAPI", "update", e); if (e.wVR == wml.PERMISSION_DENIED) { throw new fte(-4); } else if (e.wVR == wml.QUOTA_REACHED) { throw new fte(-800); } } catch (fte e2) { throw e2; } catch (Exception e3) { fqn.c("EvernoteAPI", "update", e3); } } private SparseArray<ArrayList<CSFileData>> e(CSFileData cSFileData) { SparseArray<ArrayList<CSFileData>> sparseArray = new SparseArray<>(); List<wnd> bEM = bEM(); if (bEM != null) { try { ArrayList<CSFileData> arrayList = new ArrayList<>(); ArrayList<CSFileData> arrayList2 = new ArrayList<>(); for (wnd wnd : bEM) { frh.bL(wnd.wWZ, wnd.dxN); if (wnd.wZc <= 0) { CSFileData cSFileData2 = new CSFileData(); if (!TextUtils.isEmpty(wnd.wWZ)) { cSFileData2.setFileId("LINK:" + wnd.wWZ); } else { cSFileData2.setFileId(InterstitialAdType.UNKNOW); } cSFileData2.setFolder(true); cSFileData2.setName(wnd.wZJ); cSFileData2.setRefreshTime(Long.valueOf(fun.bHG())); cSFileData2.setCreateTime(Long.valueOf(fun.bHG())); cSFileData2.setDrawableIconId(R.drawable.public_evernote_notebook_icon); cSFileData2.setPath(cSFileData2.getFileId()); cSFileData2.addParent(cSFileData.getFileId()); if (!TextUtils.isEmpty(wnd.wWZ)) { try { wmt.a sQ = sQ(wnd.wWZ); String a2 = a(wnd.wWZ, sQ); wns sV = this.gmT.sV(wnd.wWZ); if (sV == null || System.currentTimeMillis() - this.gmW > 300000) { sV = sQ.Ye(a2).wZl; this.gmT.a(wnd.wWZ, sV); } if (sV == wns.READ_NOTEBOOK || sV == wns.READ_NOTEBOOK_PLUS_ACTIVITY) { cSFileData2.setPermission(2); } } catch (wmm e) { } } else { cSFileData2.setPermission(2); } arrayList.add(cSFileData2); } else if (!TextUtils.isEmpty(wnd.wWZ)) { CSFileData cSFileData3 = new CSFileData(); if (!TextUtils.isEmpty(wnd.wWZ)) { cSFileData3.setFileId("BUSINESS:" + wnd.wWZ); } else { cSFileData3.setFileId(InterstitialAdType.UNKNOW); } cSFileData3.setFolder(true); cSFileData3.setName(wnd.wZJ); cSFileData3.setRefreshTime(Long.valueOf(fun.bHG())); cSFileData3.setCreateTime(Long.valueOf(fun.bHG())); cSFileData3.setDrawableIconId(R.drawable.public_evernote_notebook_icon); cSFileData3.setPath(cSFileData3.getFileId()); cSFileData3.addParent(cSFileData.getFileId()); try { wmt.a bEK = bEK(); String a3 = a(wnd.wWZ, bEK); wns sV2 = this.gmT.sV(wnd.wWZ); if (sV2 == null || System.currentTimeMillis() - this.gmW > 300000) { sV2 = bEK.Ye(a3).wZl; this.gmT.a(wnd.wWZ, sV2); } if (sV2 == wns.READ_NOTEBOOK || sV2 == wns.READ_NOTEBOOK_PLUS_ACTIVITY) { cSFileData3.setPermission(2); } } catch (wmm e2) { } arrayList2.add(cSFileData3); } } Collections.sort(arrayList2, frh.gnk); Collections.sort(arrayList, frh.gnk); sparseArray.append(R.string.public_evernote_business_notebook, arrayList2); sparseArray.append(R.string.public_evernote_shared_notebook, arrayList); if (System.currentTimeMillis() - this.gmW > 300000) { frg frg = this.gmT; synchronized (frg.gne) { frg.gne.clear(); } this.gmW = System.currentTimeMillis(); } return sparseArray; } catch (Exception e3) { fqn.c("EvernoteAPI", "listLinkedNotebooks", e3); } } return null; } private wno e(String str, String str2, File file) throws fte { wmt.a bEI; String stringBuffer; try { String sY = frh.sY(str); String str3 = this.gmS.token; if (!TextUtils.isEmpty(sY)) { bEI = sQ(sY); str3 = a(sY, bEI); } else { bEI = bEI(); } wne a2 = bEI.a(str3, str, true, true, true, true); if (a2.wWP > 0) { throw new fte(-2); } wno wno = new wno(); wnb wnb = new wnb(); wnb.wZx = frh.S(file); wnb.wZw = frh.R(file); wnb.setSize((int) file.length()); wnp wnp = new wnp(); wnp.xap = "file://" + file.getAbsolutePath(); wnp.fileName = str2; wnp.JD(true); wno.xcP = fqr.b.st(str2).mimeType; wno.xcO = wnb; wno.xcT = wnp; wno.active = true; wno.wVT[3] = true; a2.b(wno); if (a(a2)) { throw new fte(-804); } String str4 = a2.content; String str5 = "<en-media type=\"" + wno.xcP + "\" hash=\"" + frh.B(wno.xcO.wZw) + "\"/>"; int lastIndexOf = str4.lastIndexOf("</en-note>"); if (lastIndexOf > 0) { stringBuffer = new StringBuffer(str4).insert(lastIndexOf, str5).toString(); } else { int lastIndexOf2 = str4.lastIndexOf("/>"); StringBuffer stringBuffer2 = new StringBuffer(str4); stringBuffer2.deleteCharAt(lastIndexOf2); stringBuffer = stringBuffer2.append(str5).append("</en-note>").toString(); } a2.content = stringBuffer; bEI.b(str3, a2); List<wno> list = bEI.a(str3, str, false, false, false, false).wZS; for (int i = 0; i < list.size(); i++) { wno wno2 = list.get(i); if (wno2.xcT != null && !TextUtils.isEmpty(wno2.xcT.fileName) && wno2.xcT.fileName.trim().equals(str2) && frh.B(wno2.xcO.wZw).equals(frh.B(wno.xcO.wZw))) { return wno2; } } return wno; } catch (wmo e) { fqn.c("EvernoteAPI", "uploadFile has error.", e); if (e.wVR == wml.PERMISSION_DENIED) { throw new fte(-4); } if (e.wVR == wml.QUOTA_REACHED) { throw new fte(-800); } return null; } catch (wmm e2) { fqn.c("EvernoteAPI", "uploadFile has error.", e2); throw new fte(-2); } catch (fte e3) { throw e3; } catch (Exception e4) { fqn.c("EvernoteAPI", "uploadFile has error.", e4); return null; } } private wmj g(Uri uri) throws Exception { if (this.gmQ != null) { OAuthService bEH = bEH(); String queryParameter = uri.getQueryParameter(OAuthConstants.VERIFIER); if (queryParameter == null || queryParameter.length() == 0) { throw new Exception("cancel"); } try { return new wmj(bEH.getAccessToken(new Token(this.gmQ, this.gmR), new Verifier(queryParameter))); } catch (OAuthConnectionException e) { fqn.c("EvernoteAPI", "Failed to obtain OAuth access token", e); return null; } catch (Exception e2) { fqn.c("EvernoteAPI", "Failed to obtain OAuth access token", e2); return null; } } else { Log.d("EvernoteAPI", "Unable to retrieve OAuth access token, no request token"); return null; } } private static wmt.a sQ(String str) { try { String sZ = frh.sZ(str); frh.cG(OfficeApp.arx()); frh.bEQ(); return frh.ta(sZ); } catch (woq e) { fqn.c("EvernoteAPI", "getNoteStoreClient()", e); return null; } } private ArrayList<wne> sR(String str) { ArrayList<wne> arrayList = new ArrayList<>(); try { frg.a<List<wne>> sU = this.gmT.sU(str); if (sU == null || sU.gnf == null || sU.gng == null || sU.gng.size() == 0 || a(bEI(), this.gmS.token, sU.gnf)) { wmq wmq = new wmq(); wmq.setOrder(wng.UPDATED.value); wmq.JA(false); wmq.wWm = str; arrayList.addAll(bEI().a(this.gmS.token, wmq, 0, 1000).wWy); if (this.gmV == null) { this.gmV = a(bEI(), this.gmS.token); } this.gmT.a(str, this.gmV, arrayList); return arrayList; } arrayList.addAll(sU.gng); return arrayList; } catch (Exception e) { fqn.c("EvernoteAPI", "getNotes", e); } } private ArrayList<wne> sS(String str) { ArrayList<wne> arrayList = new ArrayList<>(); try { wmt.a sQ = sQ(str); String a2 = a(str, sQ); wnq Ye = sQ.Ye(a2); String str2 = Ye.wWm; frg.a<List<wne>> sU = this.gmT.sU(str2); if (sU == null || sU.gnf == null || sU.gng == null || a(sQ, a2, sU.gnf)) { wmq wmq = new wmq(); wmq.setOrder(wng.UPDATED.value); wmq.JA(false); wmq.wWm = Ye.wWm; arrayList.addAll(sQ.a(a2, wmq, 0, 1000).wWy); Iterator<wne> it = arrayList.iterator(); while (it.hasNext()) { frh.bK(it.next().dxl, str); } if (this.gmV == null) { this.gmV = a(sQ, a2); } this.gmT.a(str2, this.gmV, arrayList); return arrayList; } arrayList.addAll(sU.gng); return arrayList; } catch (Exception e) { fqn.c("EvernoteAPI", "getLinkedNotebookNotes", e); } } private ArrayList<wne> sT(String str) { ArrayList<wne> arrayList = new ArrayList<>(); try { wmt.a bEK = bEK(); wnx bEJ = bEJ(); String a2 = a(str, bEK); wnq Ye = bEK.Ye(a2); String str2 = Ye.wWm; frg.a<List<wne>> sU = this.gmT.sU(str2); if (sU == null || sU.gnf == null || sU.gng == null || a(bEK, a2, sU.gnf)) { wmq wmq = new wmq(); wmq.setOrder(wng.UPDATED.value); wmq.JA(false); wmq.wWm = Ye.wWm; arrayList.addAll(bEK.a(bEJ.gnE, wmq, 0, 1000).wWy); Iterator<wne> it = arrayList.iterator(); while (it.hasNext()) { frh.bK(it.next().dxl, str); } if (this.gmV == null) { this.gmV = a(bEK, a2); } this.gmT.a(str2, this.gmV, arrayList); return arrayList; } arrayList.addAll(sU.gng); return arrayList; } catch (Exception e) { fqn.c("EvernoteAPI", "getBusinessLinkedNotebookNotes", e); } } @Override // cn.wps.moffice.main.cloud.storage.core.service.internal.AbsCSAPI, defpackage.fqx public final CSFileData a(CSFileRecord cSFileRecord) throws fte { String fileId = cSFileRecord.getFileId(); if (!TextUtils.isEmpty(fileId) && fileId.contains("@_@")) { String[] split = fileId.split("@_@"); List<wno> bJ = bJ(split[0], split[1]); if (bJ != null) { if (bJ.size() == 1) { CSFileData a2 = a(bJ.get(0)); CSFileRecord tr = ftb.bGv().tr(cSFileRecord.getFilePath()); if (tr != null) { if (!a2.getFileId().equals(tr.getFileId())) { throw new fte(-2, ""); } else if (tr.getLastModify() != a2.getModifyTime().longValue()) { return a2; } } } else if (bJ.size() > 1) { throw new fte(-2, ""); } } } return null; } @Override // defpackage.fqx public final CSFileData a(String str, String str2, ftg ftg) throws fte { String str3 = str2 + ".tmp"; try { lul.fa(str2, str3); wno e = e(str, lwv.IR(str2), new File(str3)); if (e != null) { return a(e); } lul.Ip(str3); return null; } finally { lul.Ip(str3); } } @Override // defpackage.fqx public final CSFileData a(String str, String str2, String str3, ftg ftg) throws fte { String str4 = str3 + ".tmp"; try { lul.fa(str3, str4); wno d = d(str.split("@_@")[0], lwv.IR(str3), new File(str4)); if (d != null) { return a(d); } lul.Ip(str4); return null; } finally { lul.Ip(str4); } } @Override // defpackage.fqx public final synchronized List<CSFileData> a(CSFileData cSFileData) throws fte { ArrayList arrayList; ArrayList arrayList2 = new ArrayList(); if (cSFileData.equals(this.gmy)) { CSFileData cSFileData2 = new CSFileData(); cSFileData2.setFileId("2131627970"); cSFileData2.setName(OfficeApp.arx().getString(R.string.public_evernote_my_notebook)); cSFileData2.setTag(true); cSFileData2.setFolder(true); List<wnh> bEN = bEN(); if (bEN != null) { arrayList2.add(cSFileData2); ArrayList arrayList3 = new ArrayList(); for (wnh wnh : bEN) { String fileId = cSFileData.getFileId(); CSFileData cSFileData3 = new CSFileData(); cSFileData3.setFileId(wnh.dxl); cSFileData3.setFolder(true); cSFileData3.setName(wnh.name); cSFileData3.setRefreshTime(Long.valueOf(fun.bHG())); cSFileData3.setCreateTime(Long.valueOf(wnh.xaU)); cSFileData3.setModifyTime(Long.valueOf(wnh.xaV)); cSFileData3.setDrawableIconId(R.drawable.public_evernote_notebook_icon); cSFileData3.setPath(wnh.dxl); if (!TextUtils.isEmpty(fileId)) { cSFileData3.addParent(fileId); } arrayList3.add(cSFileData3); } Collections.sort(arrayList3, frh.gnk); arrayList2.addAll(arrayList3); } SparseArray<ArrayList<CSFileData>> e = e(cSFileData); if (e != null) { ArrayList<CSFileData> arrayList4 = e.get(R.string.public_evernote_business_notebook); if (arrayList4 != null && arrayList4.size() > 0) { CSFileData cSFileData4 = new CSFileData(); cSFileData4.setFileId("2131627967"); cSFileData4.setName(OfficeApp.arx().getString(R.string.public_evernote_business_notebook)); cSFileData4.setTag(true); cSFileData4.setFolder(true); arrayList2.add(cSFileData4); Collections.sort(arrayList4, frh.gnk); arrayList2.addAll(arrayList4); } ArrayList<CSFileData> arrayList5 = e.get(R.string.public_evernote_shared_notebook); if (arrayList5 != null && arrayList5.size() > 0) { CSFileData cSFileData5 = new CSFileData(); cSFileData5.setFileId("2131627975"); cSFileData5.setName(OfficeApp.arx().getString(R.string.public_evernote_shared_notebook)); cSFileData5.setTag(true); cSFileData5.setFolder(true); arrayList2.add(cSFileData5); Collections.sort(arrayList5, frh.gnk); arrayList2.addAll(arrayList5); } } arrayList = arrayList2; } else if (cSFileData.getFileId().contains(InterstitialAdType.UNKNOW)) { throw new fte(-801); } else { ArrayList<wne> sS = cSFileData.getFileId().startsWith("LINK:") ? sS(cSFileData.getFileId().replace("LINK:", "")) : cSFileData.getFileId().startsWith("BUSINESS:") ? sT(cSFileData.getFileId().replace("BUSINESS:", "")) : sR(cSFileData.getFileId()); if (sS.size() == 0) { throw new fte(-802); } for (wne wne : sS) { List<wno> list = wne.wZS; ArrayList arrayList6 = new ArrayList(); if (list != null && list.size() > 0) { for (int i = 0; i < list.size(); i++) { wno wno = list.get(i); if (fqr.sr(wno.xcP) || (wno.xcT != null && !TextUtils.isEmpty(wno.xcT.fileName) && frh.sW(wno.xcT.fileName.trim()))) { arrayList6.add(a(wno)); } } } arrayList2.add(a(wne, cSFileData.getFileId())); if (arrayList6.size() > 0) { Collections.sort(arrayList6, frh.gnk); arrayList2.addAll(arrayList6); } } arrayList = arrayList2; } return arrayList; } @Override // defpackage.fqx public final boolean a(CSFileData cSFileData, String str, ftg ftg) throws fte { if (cSFileData.getFileId().contains("@_@")) { String[] split = cSFileData.getFileId().split("@_@"); byte[] c = c(split[0], split[1], cSFileData.getModifyTime().longValue()); if (c != null) { lul.f(new ByteArrayInputStream(c), str); return true; } } return false; } @Override // cn.wps.moffice.main.cloud.storage.core.service.internal.AbsCSAPI, defpackage.fqx public final synchronized List<CSFileData> b(CSFileData cSFileData) throws fte { ArrayList arrayList; arrayList = new ArrayList(); bEO(); ArrayList<wne> bEP = bEP(); if (bEP.size() == 0) { throw new fte(-802); } for (wne wne : bEP) { List<wno> list = wne.wZS; ArrayList arrayList2 = new ArrayList(); if (list != null && list.size() > 0) { for (int i = 0; i < list.size(); i++) { wno wno = list.get(i); if ((fqr.sr(wno.xcP) || (wno.xcT != null && frh.sW(wno.xcT.fileName.trim()))) && wno.xcT != null && !TextUtils.isEmpty(wno.xcT.fileName)) { arrayList2.add(a(wno)); } } } arrayList.add(a(wne, cSFileData.getFileId())); if (arrayList2.size() > 0) { Collections.sort(arrayList2, frh.gnk); arrayList.addAll(arrayList2); } } return arrayList; } @Override // cn.wps.moffice.main.cloud.storage.core.service.internal.AbsCSAPI, defpackage.fqx public final boolean b(CSFileData cSFileData, String str) throws fte { try { String fileId = cSFileData.getFileId(); wne wne = new wne(); wne.title = str; wne.content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\"><en-note></en-note>"; if (fileId.startsWith("LINK:")) { String replaceFirst = fileId.replaceFirst("LINK:", ""); wmt.a sQ = sQ(replaceFirst); String a2 = a(replaceFirst, sQ); wne.wWm = sQ.Ye(a2).wWm; sQ.a(a2, wne); } else if (fileId.startsWith("BUSINESS:")) { String replaceFirst2 = fileId.replaceFirst("BUSINESS:", ""); wmt.a bEK = bEK(); wnx bEJ = bEJ(); wne.wWm = bEK.Ye(a(replaceFirst2, bEK)).wWm; bEK.a(bEJ.gnE, wne); } else { wne.wWm = fileId; bEI().a(this.gmS.token, wne); } return true; } catch (Exception e) { if (e instanceof wmm) { throw new fte(-2); } else if (!(e instanceof wmo) || ((wmo) e).wVR != wml.QUOTA_REACHED) { fqn.c("EvernoteAPI", "newNote", e); return false; } else { throw new fte(-800); } } } @Override // defpackage.fqx public final boolean bE(String str, String str2) throws fte { if (TextUtils.isEmpty(str) || !str.contains("@_@")) { return false; } String[] split = str.split("@_@"); return Q(split[0], split[1], str2) != null; } @Override // defpackage.fqx public final CSFileData bEA() throws fte { if (this.gmy == null) { this.gmy = new CSFileData(); CSConfig tq = fta.bGu().tq(this.fIH); this.gmy.setFileId(tq.getName()); this.gmy.setName(OfficeApp.arx().getString(fqo.sk(tq.getType()))); this.gmy.setFolder(true); this.gmy.setPath(OfficeApp.arx().getString(fqo.sk(tq.getType()))); this.gmy.setRefreshTime(Long.valueOf(fun.bHG())); this.gmy.setCreateTime(Long.valueOf(fun.bHG())); } return this.gmy; } @Override // defpackage.fqx public final boolean bEx() { this.glC.a(this.gmn); this.gmL.clear(); frh.bER(); frh.bES(); ful.wF(1); ful.wG(-1); ful.mx(false); frg frg = this.gmT; frg.gna = new frg.a<>(null, new ArrayList()); frg.gnb = new frg.a<>(null, new ArrayList()); frg.gnc = new HashMap<>(); frg.gnd = new frg.a<>(null, new ArrayList()); frg.gne = new HashMap<>(); this.gmK.clear(); this.gmK = null; this.gmO = null; this.gmY = null; this.gmM = null; this.gmN = null; return true; } @Override // cn.wps.moffice.main.cloud.storage.core.service.internal.AbsCSAPI, defpackage.fqx public final String bEy() throws fte { int i = 3; String str = null; while (true) { int i2 = i - 1; try { OAuthService bEH = bEH(); Token requestToken = bEH.getRequestToken(); this.gmQ = requestToken.getToken(); this.gmR = requestToken.getSecret(); str = bEH.getAuthorizationUrl(requestToken); break; } catch (Exception e) { fqn.c("EvernoteAPI", "getOAuthURL", e); if (!(e instanceof SSLException)) { if (lwd.hu(OfficeApp.arx())) { throw new fte(e); } throw new fte(-1, e); } else if (i2 > 0) { i = i2; } else if (TextUtils.isEmpty(str)) { throw new fte(-1, "cant load url."); } } } return str; } @Override // cn.wps.moffice.main.cloud.storage.core.service.internal.AbsCSAPI, defpackage.fqx public final List<CSFileData> bF(String str, String str2) throws fte { ArrayList arrayList = new ArrayList(); if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) { return arrayList; } List<wno> bJ = bJ(str, str2); int i = 0; while (bJ != null && i < bJ.size()) { arrayList.add(a(bJ.get(i))); i++; } return arrayList; } @Override // cn.wps.moffice.main.cloud.storage.core.service.internal.AbsCSAPI, defpackage.fqx public final String getRedirectUrl() { return "en-kso-android-agent://callback"; } @Override // cn.wps.moffice.main.cloud.storage.core.service.internal.AbsCSAPI, defpackage.fqx public final boolean h(boolean z, String str) { wnh wnh = new wnh(); wnh.name = str; if (!z) { try { bEI().a(this.gmS.token, wnh); } catch (Exception e) { fqn.c("EvernoteAPI", "newNoteBook", e); return false; } } else { wnx bEJ = bEJ(); wnh a2 = bEK().a(bEJ.gnE, wnh); wnd wnd = new wnd(); wnd.wWZ = a2.xaZ.get(0).wWZ; wnd.wZJ = a2.name; wnd.username = bEJ.xfg.username; wnd.wZK = bEJ.xfg.wZK; wmt.a bEI = bEI(); bEI.a(this.gmS.token, wnd); bEI.fYa(); } return true; } @Override // cn.wps.moffice.main.cloud.storage.core.service.internal.AbsCSAPI, defpackage.fqx public final boolean q(String... strArr) throws fte { String str = strArr[0]; try { wmj g = g(Uri.parse(str)); if (g == null) { return false; } dgq dgq = new dgq(); dgq.token = g.getToken(); dgq.dxN = g.wVn; dgq.dxO = g.wVo; String valueOf = String.valueOf(g.wVp); this.gmn = new CSSession(); this.gmn.setKey(this.fIH); this.gmn.setLoggedTime(System.currentTimeMillis()); this.gmn.setPassword(JSONUtil.toJSONString(dgq)); this.gmn.setToken(JSONUtil.toJSONString(dgq)); this.gmn.setUserId(valueOf); this.gmn.setUserId(valueOf); this.glC.b(this.gmn); bEG(); bEO(); if (ful.aEz() == 1) { cqh.c s = cqr.s(OfficeApp.arx(), "public_login_evernote"); s.cpH = "UA-31928688-36"; s.cpI = false; OfficeApp.arx().arN(); return true; } else if (ful.aEz() != 2) { return true; } else { cqh.c s2 = cqr.s(OfficeApp.arx(), "public_login_印象笔记"); s2.cpH = "UA-31928688-36"; s2.cpI = false; OfficeApp.arx().arN(); return true; } } catch (Exception e) { fqn.c("EvernoteAPI", "handleUrl(String url)" + str, e); return false; } } @Override // defpackage.fqx public final CSFileData sK(String str) throws fte { if (str.contains("@_@")) { String[] split = str.split("@_@"); List<wno> bJ = bJ(split[0], split[1]); if (bJ != null && bJ.size() > 0) { return a(bJ.get(0)); } } return null; } }